package game.groves.hollow;

import android.graphics.Bitmap;
import android.graphics.Canvas;

public class Parallax{
	
	Bitmap image;
	int[] positions;
	int imageCount;
	int imageWidth;
	int screenWidth;
	int speed;
	int farLeftPosition;
	
	public Parallax(Bitmap image, int screenWidth, int speed){
		this.image = image;
		this.screenWidth = screenWidth;
		this.speed = speed;
		this.imageWidth = image.getWidth();
		this.imageCount = ((screenWidth/imageWidth) + 2);
		this.positions = new int[imageCount];
		for (int i = 0; i < positions.length; i++){
			positions[i] = ((i - 1) * imageWidth);
		}
		farLeftPosition = positions[0];
		
	}
	
	public void update(){
		farLeftPosition += speed;
		for (int i = 0; i < positions.length; i++){
			positions[i] += speed;
			if(positions[i] >= screenWidth){
				positions[i] = farLeftPosition - imageWidth;
				farLeftPosition = positions[i];
			}
		}
		
	}
	
	public void draw(Canvas canvas){
		for (int i = 0; i < positions.length; i++){
			canvas.drawBitmap(image, positions[i], 0, null);
		}
	}
}